<?php
namespace app\admin\model;
/*
 *表名
 */
class GroupModel extends BaseModel
{
    protected $table = 'xst_group';
    protected $rule = [
        'id' => '',
    ];
    protected $msg = [
        'id' => '',
    ];
    //查询所有数据并分页
    public function AllData()
    {
        $list=$this->paginate(10);
        $page = $list->render();
        $arr=[$list,$page];
        return $arr;
    }
    //查询所有数据不分页
    public function AllDataNF()
    {
        $list=$this->select();
        return $list;
    }
    //权限组的禁止和启用
    public function IsStatus($id,$status){
        $res=$this->where('id',$id)->update(['status'=>$status]);
        if($res){
            if ($status==1)
                $status = ['code'=>1,'msg'=>'开启成功'];
            else
                $status = ['code'=>1,'msg'=>'已禁用'];
        }else{
            if ($status==1)
                $status = ['code'=>0,'msg'=>'开启失败'];
            else
                $status = ['code'=>0,'msg'=>'禁用失败'];
        }
        return $status;
    }
    //查询单条管理组的规则id，并转化成数组
    public function onerules($id){
        $res=$this->where('id',$id)->find();
        $res['rulesid']=explode(',',$res['rulesid']);
        return $res;
    }
    //修改管理组信息
    public function updategroups($id,$rules,$name){
        $result = $this->where('id',$id)->update(['rulesid'=>$rules,'name'=>$name]);
        if ($result)
            $status = ['code'=>1,'msg'=>'修改成功'];
        else
            $status = ['code'=>0,'msg'=>'修改失败'];
        return $status;
    }
    //添加管理组信息
    public function addgroup($title,$rules){
        $result =  $this->save(['rulesid'=>$rules,'name'=>$title]);
        if ($result)
            $status = ['code'=>1,'msg'=>'添加成功'];
        else
            $status = ['code'=>0,'msg'=>'添加失败'];
        return $status;
    }
}
